#include "other.h"

static unsigned char g_ph_initialized = 0;

//=====================================================================
//                    Photon common functions
//=====================================================================

static PyObject* init (PyObject* self)
{
  PyObject* result;

  if (PtInit(NULL) == -1)
  {
    PyErr_SetString (PyExc_RuntimeError, 
        "Unable to initialize photon library");
    return NULL;
  }

  g_ph_initialized = 1;

  Py_INCREF (Py_None);
  result = Py_None;

  return result;
}

static PyObject* main_loop (PyObject* self)
{
  PyObject* result;

  if (!g_ph_initialized)
  {
    PyErr_SetString (PyExc_RuntimeError, 
        "No connection to Photon library");
    return NULL;
  }

  PtMainLoop ();

  Py_INCREF (Py_None);
  result = Py_None;

  return result;
}

static PyMethodDef module_methods [] = 
{
  {"init", init, METH_NOARGS, "Connect to Photon library"},
  {"main_loop", main_loop, METH_NOARGS, "Photon listener"},
  {NULL, NULL, 0, NULL}
};

PyMODINIT_FUNC 
initph_api_other (void)
{
  PyObject *m;

  m = Py_InitModule ("ph_api_other", module_methods);

  if (m == NULL)
    return;
}

